#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5+5,mod = 1e9+7;
int n,ls[N],rs[N],_ls[N],_rs[N],f[N],_f[N],ans[N],dep[N];
void splay(int x)
{
	int fa = f[x];
	if(ls[f[x]]==x)
		ls[f[x]] = rs[x],f[rs[x]] = f[x],rs[x] = f[x],f[x] = f[f[x]];
	else rs[f[x]] = ls[x],f[ls[x]] = f[x],ls[x] = f[x],f[x] = f[f[x]];
	if(ls[f[fa]]==fa) ls[f[fa]] = x;
	else rs[f[fa]] = x;
	f[fa] = x; 
}
void dfs(int x)
{
	if(x==0) return;
	ans[x]+=(dep[x] = dep[f[x]]+1);
	dfs(ls[x]),dfs(rs[x]);
}
signed main()
{
	freopen("dream.in","r",stdin);
	freopen("dream.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i = 1;i<=n;i++)
		cin>>_ls[i]>>_rs[i],_f[_ls[i]] = _f[_rs[i]] = i;
	_f[0] = 0;
	if(n<=2000)
	{
		for(int x = 1;x<=n;x++)
		{
			memcpy(f,_f,sizeof f);
			memcpy(ls,_ls,sizeof ls);
			memcpy(rs,_rs,sizeof rs);
			while(f[x])
			{
				int fa = f[x];
				if(f[fa]==0) splay(x);
				else if((ls[f[x]]==x&&ls[f[fa]]==fa)||(rs[f[x]]==x&&rs[f[fa]]==fa))
					splay(fa),splay(x);
				else splay(x),splay(x);
			}
			dep[0] = -1;
			dfs(x);
		}
		for(int i = 1;i<=n;i++)
			cout<<ans[i]<<'\n';
	}
	else
	{
		for(int i = 1;i<=n;i++)
		{
			int sum = (i-1)*(1+i-1)/2,op1,op2;
			op1 = (i+1)/2,op2 = op1+1;
			if(i%2==0) op2++;
			int add = (n-i)/2*(op1+op2);
			if((n-i)%2) add+=op1;
			cout<<sum+add<<'\n';
		}
	}
	return 0;
}

